package com.herohead.redis;

import java.util.Set;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;



public class getConfig {

	static PropertiesConfiguration config;
	public static JSONObject getJsonBoject(String json){
		JSONParser parser = new JSONParser();
		Object obj1 = null;
		try {
			obj1 = parser.parse(json);
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			obj1 = parser.parse(json);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return (JSONObject) obj1;
	}

	@SuppressWarnings("rawtypes")
	public static Set getKeysJson(JSONObject json){
		return json.keySet();
	}

	@SuppressWarnings("rawtypes")
	public static Set getKeysJson(String json){
		return getKeysJson(getJsonBoject(json));
	}

	public static String getValueJson(String json, String key){
		return getJsonBoject(json).get(key).toString();
	}

	String configKey;
	@SuppressWarnings("unchecked")
	public String readConf(String confFile) {
		JSONObject jsobj = new JSONObject();

		try {
			config = new PropertiesConfiguration(confFile);
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		jsobj.put("redisServer", config.getString("redisServer"));
		jsobj.put("redisConfKey", config.getString("redisConfKey"));

		return jsobj.toJSONString();
	}


	public void setConfKey(String strConfigKey) {
		configKey = strConfigKey;
	}


}

